package com.ksu.manager.ajax;

import java.util.List;

import com.ksu.manager.model.Product;
import com.ksu.manager.model.TypeItem;
import com.ksu.manager.model.User;
import com.ksu.manager.service.IProductService;
import com.ksu.manager.service.ITypeItemService;
import com.ksu.manager.service.IUserService;

public class ManagerAjax {

	private ITypeItemService typeItemService;

	private IProductService productService;
	
	private IUserService userService;
	
	public IUserService getUserService() {
		return userService;
	}



	public void setUserService(IUserService userService) {
		this.userService = userService;
	}



	public IProductService getProductService() {
		return productService;
	}



	public void setProductService(IProductService productService) {
		this.productService = productService;
	}



	public ITypeItemService getTypeItemService() {
		return typeItemService;
	}



	public void setTypeItemService(ITypeItemService typeItemService) {
		this.typeItemService = typeItemService;
	}



	public List<TypeItem> getSubTypeItemList(int typeItemId){
		TypeItem typeItem = new TypeItem();
		typeItem.setParentId(typeItemId);
		return typeItemService.queryList(typeItem);
	}
	
	public List<Product> getProductList(int typeItemId){
		Product product = new Product();
		product.setTypeItemId(typeItemId);
		return productService.queryList(product);
	}
	
	public List<Product> getProductListByName(String name){
		Product product = new Product();
		product.setName(name);
		return productService.queryListByName(product);
	}
	
	public List<TypeItem> getTypeItemListByName(String displayName){
		TypeItem typeItem = new TypeItem();
		typeItem.setDisplayName(displayName);
		return typeItemService.queryList(typeItem);
	}
	
	public List<User> getUserListByName(String loginName){
		User user = new User();
		user.setLoginName(loginName);
		return userService.queryList(user);
	}
	
	public String[] checkNameAndNo(String productName,String productNo){
		String result[] = new String[2];
		List<Product> productList = null;
		Product product = new Product();
		Product productTemp = new Product();
		product.setName(productName);
		productList = productService.queryListByName(product);
		if(productList!=null && productList.size()>0){
			result[0] = "nameRepeat";
		}
		productTemp.setNo(productNo);
		productList = productService.queryListByName(productTemp);
		if(productList!=null && productList.size()>0){
		    result[1] = "noRepeat";
		}
		
		return result;
	}
	
	
}
